package LeetCode;

import java.math.BigInteger;
import java.util.Scanner;

public class LC_007_ReverseInteger {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            System.out.println(reverse(n));
        }
        sc.close();
    }

    private static int reverse(int x) {
        StringBuilder sb = new StringBuilder(String.valueOf(x));
        String rx = x >= 0 ? sb.reverse().toString() : sb.deleteCharAt(0).reverse().toString();
        int n1 = new BigInteger(String.valueOf(Integer.MAX_VALUE)).compareTo(new BigInteger(rx));
        int n2 = new BigInteger(String.valueOf(Integer.MIN_VALUE)).compareTo(new BigInteger(rx));
        if (x < 0 && n1 >= 0 && n2 <= 0)
            return Integer.parseInt("-" + rx);
        else if (x >= 0 && n1 >= 0 && n2 <= 0)
            return Integer.parseInt(rx);
        else
            return 0;
    }
}